package com.iring.util.common;

import java.util.Random;

/**
 * 字符串工具类
 *
 * @author wanggan
 */
public class StringUtil {


    public static Boolean isEmpty(Object object){

        if(object instanceof String){
            String str = (String) object;
            return null == object || str.trim().equals("") ?true:false;
        }else if(object instanceof Integer){
            return null == object ?true:false;
        }
        return null == object ?true:false;

    }

    /**
     * 获取随机字符串
     * 
     * @param length
     *            所需生成字符串长度
     * @return 生成的字符串
     */
    public static String getRandomString(int length) {
        String str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        Random random = new Random();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < length; ++i) {
            int number = random.nextInt(62);
            sb.append(str.charAt(number));
        }
        return sb.toString();
    }

    public static String getRandomNumberStr(int length) {
        String str = "0123456789";
        Random random = new Random();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < length; ++i) {
            int number = random.nextInt(10);
            sb.append(str.charAt(number));
        }
        return sb.toString();
    }

}
